﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>授权详细信息</title>
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />
    <link href="../Scripts/bootstrap/css/bootstrap.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/components-rounded.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/font-awesome.css" rel="stylesheet" />
    <link href="../Scripts/bootstrap/css/themes/default/style.min.css" rel="stylesheet" />
    <script type="text/javascript" src="../Scripts/QueryString.js"></script>
    <script type="text/javascript" src="../Scripts/QueryString2016.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/jquery.cokie.min.js"></script>
    <script type="text/javascript" src="../Scripts/bootstrap/js/bootstrap.min.js"></script>
    <link href="../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
    <!--时间-->
    <script src="../Comm/JS/Calendar/WdatePicker.js" type="text/javascript"></script>
    <link href="../Comm/JS/Calendar/skin/WdatePicker.css" rel="stylesheet" type="text/css" />
    <!-- 导入配置文件. -->
    <script type="text/javascript" src="../Scripts/config.js"></script>
    <script type="text/javascript" src="../Comm/Gener.js"></script>
    <script type="text/javascript" language="javascript">
        //页面启动函数.
        var webUser = null;
        var emp = null;

        $(function () {

            webUser = new WebUser();

            var ens = new Entities("BP.WF.Auths");
            ens.Retrieve("Auther", webUser.No);


           var  html = "<div class='container'>";
           html += "<div class='fixed-table-header '>";
           html += "<table class='table table-hover table-striped ' >";
           html += "<caption style='height:auto;text-indent: 0em;'> [" + webUser.No + "]授权列表  <a href='AuthorDtl.htm' >+增加授权列表</a> </caption>";
            
           html += "<thead ><tr> ";
           html += "<th style='background-color:#F2F2F2;'>序</th>";
           html += "<th style='background-color:#F2F2F2;'>授权给</th>";
           html += "<th style='background-color:#F2F2F2;'>授权类型</th>";
           html += "<th style='background-color:#F2F2F2;'>流程</th>";
           html += "<th style='background-color:#F2F2F2;'>收回日期</th>";
           html += "<th style='background-color:#F2F2F2;'>状态</th>";
           html += "<th style='background-color:#F2F2F2;'>操作</th>";
           html += "</tr></thead>";


            html += "<tbody>";
            var takeBackDT = "";
            var num = 1;
            for (var i = 0; i < ens.length; i++) {

                en = ens[i];
                //指定流程时，授权时间不同，可能会有多条合并流程的记录
                if (en.AuthType == 2) {
                    if (takeBackDT.indexOf(en.TakeBackDT+",") != -1) {
                            continue;
                    }
                    takeBackDT += en.TakeBackDT + ",";

                    var sql = "SELECT EmpNo, FlowName FROM WF_Auth WHERE AuthType = 2 and Auther = '" + webUser.No + "' and EmpNo = '" + en.EmpNo + "' and TakeBackDT = '" + en.TakeBackDT + "'";
                    var dt = DBAccess.RunSQLReturnTable(sql);
                    
                    var flowName = "";
                    for (var j = 0; j < dt.length; j++) {
                    
                        var da = dt[j];
                        flowName += da.FlowName + ",";
                    }
                }
                var AuthType = en.AuthType;
                var AuthTypeName;
                switch (AuthType) {
                    case 0: AuthTypeName='不授权' ; break;
                    case 1: AuthTypeName='全部流程授权'; break;
                    case 2: AuthTypeName='指定流程授权';break;
                    default: AuthTypeName = '空'; 
                }
                var nowDate = getNowFormatDate();
                var state = "";
                if (nowDate<=en.TakeBackDT) {
                    state = "授权中";
                } else {
                    state = "已收回";
                }
                
                html += "<tr>";
                html += "<td>" + num + "</td>";
                html += "<td>" + en.EmpName + "</td>";
                html += "<td>" + AuthTypeName + "</td>";
                if (en.AuthType == 2) {
                    html += "<td>" + flowName + "</td>";
                } else {
                    html += "<td>" + en.FlowName + "</td>";
                }
                html += "<td>" + en.TakeBackDT + "</td>";
                html += "<td>" + state + "</td>";
                html += "<td><a href=\"javascript:Del('" + en.Auther + "','" + en.EmpNo + "','" + en.TakeBackDT + "')\">删除</a></td>";
                html += "</tr>";
                num++;
            }

            html += "</tbody>";
            html += "</table>";
            html += "</div>";
            html += "</div>";
            $("#docs").html(html);
           
        });

        //执行删除.
        function Del(Auther,EmpNo,TakeBackDT) {
            if (window.confirm('您确定要删除吗？') == false)
                return;
            var sql = "delete FROM WF_Auth where Auther = '" + Auther + "' and EmpNo = '" + EmpNo + "' and TakeBackDT = '" + TakeBackDT + "'";
            DBAccess.RunSQL(sql);
            alert("删除成功");
            window.location.href = window.location.href;

        }
        //获取当前时间
        function getNowFormatDate() {
            var date = new Date();
            var seperator1 = "-";
            var seperator2 = ":";
            var month = date.getMonth() + 1;
            var strDate = date.getDate();
            if (month >= 1 && month <= 9) {
                month = "0" + month;
            }
            if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
            }
            //当前时间=年份-月份-日 小时：分钟
            var cdt = date.getFullYear() + seperator1 + month + seperator1 + strDate;
            //+ " " + date.getHours() + seperator2 + date.getMinutes();

            return cdt;
        }

</script>
</head>
<body onkeypress="Esc()" class="gray-bg">
    <form id="cc" name="cc">
        <div id="docs"></div>

    </form>
</body>
</html>
